package com.tencent.cloud.iov.common.flow.view.impl;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import com.tencent.cloud.iov.common.flow.view.ILoadingFlowView;
import com.tencent.cloud.iov.flow.presenter.IPresenter;
import com.tencent.cloud.iov.flow.view.IContentViewContainer;
import com.tencent.cloud.iov.recycler.flow.BaseRecyclerFlowView;
import com.tencent.cloud.uikit.ui.widget.IovLoadingView;

/**
 * @author showxiao
 * @date 2018/10/15
 */
public abstract class BaseLoadingRecyclerFlowView<P extends IPresenter> extends BaseRecyclerFlowView<P>
        implements ILoadingFlowView {

    private ILoadingFlowView mDelegate;

    public BaseLoadingRecyclerFlowView(Activity activity) {
        super(activity);
    }

    public BaseLoadingRecyclerFlowView(Activity activity, IContentViewContainer container) {
        super(activity, container);
    }

    @Override
    public void setContentView(int resId) {
        ensureDelegate();
        mDelegate.setContentView(resId);
    }

    @Override
    public void setContentView(View contentView) {
        ensureDelegate();
        mDelegate.setContentView(contentView);
    }

    @Override
    public void setContentView(View contentView, ViewGroup.LayoutParams params) {
        ensureDelegate();
        mDelegate.setContentView(contentView, params);
    }

    @Override
    public void superSetContentView(View contentView, ViewGroup.LayoutParams params) {
        super.setContentView(contentView, params);
    }

    @Override
    public final void showLoadingView() {
        ensureDelegate();
        mDelegate.showLoadingView();
    }

    @Override
    public final void showLoadingView(CharSequence text) {
        ensureDelegate();
        mDelegate.showLoadingView(text);
    }

    @Override
    public final void hideLoadingView() {
        ensureDelegate();
        mDelegate.hideLoadingView();
    }

    @Override
    public IovLoadingView createLoadingView() {
        return new IovLoadingView(getContext());
    }

    private void ensureDelegate() {
        if (mDelegate == null) {
            mDelegate = new DefaultLoadingFlowView(this);
        }
    }
}
